import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.*;

public class Main {

    static  String ed;
    static long res;
    public  static void bc(int k,String s)
    {
        if(k==0)
        {
            if(s.equals(ed)) res++;
            return;
        }
        StringBuilder stringBuilder = new StringBuilder();
        for(int r=0;r<s.length()-1;r++)
        {
            stringBuilder.append(s.charAt(r));
            bc(k-1,s.substring(r+1)+stringBuilder.toString());
        }

    }
    public static void main(String args[]) {
        //k1x+b1=k2x+b2
        // x= b2-b1 / k1-k2
        //y=-k2b1+k1b2 / k1-k2
        Scanner scanner=new Scanner(System.in);
        String s=scanner.next(),e=scanner.next();
        int[] cnt=new int[26];
        if(s.length()!=e.length()){
            System.out.println(0);
            return;
        }
        for (int i = 0; i < s.length(); i++) {
            cnt[s.charAt(i)-'a']++;
        }
        for (int i = 0; i < e.length(); i++) {
            cnt[e.charAt(i)-'a']--;
        }
        for(int i=0;i<26;i++)
            if(cnt[i]!=0) {
                System.out.println(0);
                return;
            }

        ed=e;
        int k=scanner.nextInt();
        bc(k,s);
        res%=1000000007;
        System.out.println((int)res);



    }
}
